/*
 *  Class name: ClockMenu.java
 *  Version: 1.0
 *  Date: 7.12.2013
 */
package cz.muni.fi.pa165.soccergamesarchive.restclient.gui.components;

import java.awt.event.ActionEvent;
import java.text.DateFormat;
import java.util.Date;
import javax.swing.JMenu;
import javax.swing.Timer;

import static java.text.DateFormat.getDateTimeInstance;
import static java.util.Calendar.getInstance;

/**
 *
 * @author Michal Ďuriš
 */
public class ClockMenu extends JMenu {

    private static final long serialVersionUID = 1L;

    /**
     * Creates new form ClockMenu
     */
    public ClockMenu() {
        initComponents();
        setActualTime();
        activateClocks();
    }

    private void setActualTime() {
        this.setText(getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM)
                .format(new Date(getInstance().getTimeInMillis())));
    }

    private void activateClocks() {

        new Timer(1000, (ActionEvent e) -> {
            setActualTime();
        }).start();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setEnabled(false);
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
